<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var n = prompt("输入一个值n，打印斐波那契数列前n项：") * 1;
      function FBNQ(num) {
        var f0 = 0,
          f1 = 1,
          f2 = 0;
        if (n >= 1) {
          document.write("第1项：" + f1 + "<br>");
        }
        for (var i = 2; i <= num; i++) {
          f2 = f0 + f1;
          f0 = f1;
          f1 = f2;
          document.write("第" + i + "项：" + f2 + "<br>");
        }
      }
      FBNQ(n);
    </script>
  </body>
</html>
